//
//  BillTypeSelect.swift
//  Speek
//
//  Created by MikeHo on 2023/6/29.
//

import SwiftUI

struct BillTypeSelect: View {
    
    // View Properties
    @State private var seeAllOutput = false
    @State private var seeAllIncome = false
    @Binding var isSelected : Bool
    @Binding var selectType : String
    
    // Emvironment Properties
    @Environment(\.dismiss) private var dismiss
    @Environment(\.managedObjectContext) private var context
    
    
    var body: some View {
        NavigationStack{
            ScrollView{
                VStack{
                    Section(
                        header:Text("支出")
                            .font(.title2)
                            .bold()
                    ){
                        HStack(spacing: 10){
                            Button {
                                isSelected = true
                                selectType = "学习"
                                dismiss()
                            } label: {
                                VStack{
                                    Image("学习")
                                        .padding()
                                        .background(Color.white.cornerRadius(15))
                                    Text("学习")
                                }
                            }
                            
                            Button {
                                isSelected = true
                                selectType = "医疗"
                                dismiss()
                            } label: {
                                VStack{
                                    
                                    Image("医疗")
                                        .padding()
                                        .background(Color.white.cornerRadius(15))
                                    
                                    Text("医疗")
                                }
                            }
                            
                            Button {
                                isSelected = true
                                selectType = "饮食"
                                dismiss()
                            } label: {
                                VStack{
                                    
                                    Image("饮食")
                                        .padding()
                                        .background(Color.white.cornerRadius(15))
                                    
                                    Text("饮食")
                                }
                            }
                            
                            Button {
                                isSelected = true
                                selectType = "维修"
                                dismiss()
                            } label: {
                                VStack{
                                    
                                    Image("维修")
                                        .padding()
                                        .background(Color.white.cornerRadius(15))
                                    
                                    Text("维修")
                                    
                                }
                            }
                        }
                        HStack(spacing: 10){
                            Button {
                                isSelected = true
                                selectType = "旅行"
                                dismiss()
                            } label: {
                                VStack{
                                    
                                    Image("旅行")
                                        .padding()
                                        .background(Color.white.cornerRadius(15))
                                    Text("旅行")
                                }
                            }
                            
                            Button {
                                isSelected = true
                                selectType = "运动"
                                dismiss()
                            } label: {
                                VStack{
                                    
                                    Image("运动")
                                        .padding()
                                        .background(Color.white.cornerRadius(15))
                                    Text("运动")
                                }
                            }
                            
                            Button {
                                isSelected = true
                                selectType = "娱乐"
                                dismiss()
                            } label: {
                                VStack{
                                    
                                    Image("娱乐")
                                        .padding()
                                        .background(Color.white.cornerRadius(15))
                                    Text("娱乐")
                                }
                            }
                            
                            Button {
                                isSelected = true
                                selectType = "购物"
                                dismiss()
                            } label: {
                                VStack{
                                    
                                    Image("购物")
                                        .padding()
                                        .background(Color.white.cornerRadius(15))
                                    Text("购物")
                                }
                            }
                        }
                        if seeAllOutput{
                            HStack(spacing: 10){
                                Button {
                                    isSelected = true
                                    selectType = "理财"
                                    dismiss()
                                } label: {
                                    VStack{
                                        
                                        Image("理财")
                                            .padding()
                                            .background(Color.white.cornerRadius(15))
                                        Text("理财")
                                    }
                                }
                                .padding(.leading,18)
                                
                                Button {
                                    isSelected = true
                                    selectType = "其他"
                                    dismiss()
                                    
                                } label: {
                                    VStack{
                                        
                                        Image("其他")
                                            .padding(18)
                                            .background(Color.white.cornerRadius(15))
                                        Text("其他")
                                    }
                                }
                                Spacer()
                                /*
                                 Button {
                                 
                                 } label: {
                                 
                                 Text("")
                                 }
                                 
                                 Button {
                                 
                                 } label: {
                                 
                                 Text("")
                                 }
                                 Spacer()
                                 */
                            }
                        }else{
                            
                            HStack{
                                Spacer()
                                Button{
                                    seeAllOutput = true
                                }label:{
                                    Text("See All")
                                        .bold()
                                        .padding(.vertical,5)
                                        .padding(.horizontal,10)
                                        .foregroundColor(.black)
                                        .background(Color.white.cornerRadius(10))
                                }
                                Spacer()
                            }
                        }
                        
                    }
                    .foregroundColor(.white)
                    .padding(.bottom,20)
                    
                    
                    Section(header:Text("收入").font(.title2).bold()){
                        HStack(spacing:10){
                            Button {
                                isSelected = true
                                selectType = "礼物"
                                dismiss()
                            } label: {
                                VStack{
                                    
                                    Image("礼物")
                                        .padding()
                                        .background(Color.white.cornerRadius(15))
                                    Text("礼物")
                                }
                            }
                            
                            Button {
                                isSelected = true
                                selectType = "理财"
                                dismiss()
                            } label: {
                                VStack{
                                    
                                    Image("理财")
                                        .padding()
                                        .background(Color.white.cornerRadius(15))
                                    Text("理财")
                                }
                            }
                            
                            Button {
                                isSelected = true
                                selectType = "奖学金"
                                dismiss()
                            } label: {
                                VStack{
                                    
                                    Image("奖学金")
                                        .padding()
                                        .background(Color.white.cornerRadius(15))
                                    Text("奖学金")
                                }
                            }
                            
                            Button {
                                isSelected = true
                                selectType = "工资"
                                dismiss()
                            } label: {
                                VStack{
                                    
                                    Image("工资")
                                        .padding()
                                        .background(Color.white.cornerRadius(15))
                                    Text("工资")
                                }
                            }
                        }
                        
                        if seeAllIncome{
                            HStack(spacing: 10){
                                Button {
                                    isSelected = true
                                    selectType = "其他"
                                    dismiss()
                                } label: {
                                    VStack{
                                        
                                        Image("其他")
                                            .padding(18)
                                            .background(Color.white.cornerRadius(15))
                                        Text("其他")
                                    }
                                }
                                .padding(.leading,18)
                                Spacer()
                                /*
                                 Button {
                                 
                                 } label: {
                                 Image("其他")
                                 Text("其他")
                                 }
                                 
                                 Button {
                                 
                                 } label: {
                                 Image("娱乐")
                                 Text("娱乐")
                                 }
                                 
                                 Button {
                                 
                                 } label: {
                                 Image("购物")
                                 Text("购物")
                                 }
                                 */
                            }
                        }else{
                            
                            HStack{
                                Spacer()
                                Button{
                                    seeAllIncome = true
                                }label:{
                                    Text("See All")
                                        .bold()
                                        .padding(.vertical,5)
                                        .padding(.horizontal,10)
                                        .foregroundColor(.black)
                                        .background(Color.white.cornerRadius(10))
                                }
                                Spacer()
                            }
                        }
                    }
                    .foregroundColor(.white)
                    
                }
            }
            .preferredColorScheme(.dark)
            .navigationTitle("选择分类")
            .toolbar{
                //重置按钮
                ToolbarItem(placement: .navigationBarTrailing){
                    Button {
                        isSelected = false
                        selectType = ""
                        dismiss()
                    } label: {
                        Image(systemName: "arrow.clockwise")
                            .foregroundColor(.white)
                    }
                }
                
                
            }
            
        }
    }
}
